
package com.ruoyi.gisconverter.core;




import com.ruoyi.gisconverter.ext.ExtensionsUtil;
import com.ruoyi.gisconverter.ext.FileExtension;
import org.apache.commons.io.FilenameUtils;
import org.geotools.data.FeatureSource;

import java.io.File;


public class ConvertProcess {

    private File file;
    private FileExtension ext;
    private String currentFileExt;

    public ConvertProcess() {
    }

    public ConvertProcess(File file, FileExtension ext) {
        this.file = file;
        this.ext = ext;
    }

    public void execute() {
        ExtensionsUtil extUtil = new ExtensionsUtil();
        currentFileExt = FilenameUtils.getExtension(file.getAbsolutePath());
        FileExtension fileExtension = extUtil.getFileExtension(currentFileExt);
        FeatureSource fs = fileExtension.getFileProcess().readFile(file);

        String name = FilenameUtils.getBaseName(file.getAbsolutePath());
        File output = new File(file.getParent() + File.separator + name + "." + ext.getExtension());
        ext.getFileProcess().writeFile(fs, output);
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public FileExtension getExt() {
        return ext;
    }

    public void setExt(FileExtension ext) {
        this.ext = ext;
    }

}
